import {
	baseApi_,
	ONLINE_SERVER_USER,
	tokenRequestP,
	tokenRequest,
	uniRequest,
	getUserRight,
} from './network';
import {
	clearUserInfo,
	CURRENT_USER_KEY,
	d_uniShowToast,
	FINE_LOCATION,
	MY_LOCATION,
	PROFILE_OF,
	SHORT_TOAST_DURATION,
	TOAST_DURATION,
	TOKEN_key,
	uniShowToast,
} from './misc';
import Config, {
	USER_ORIENTED
} from './config';

import QQMapSdk from '../util/newSDK/qqmap-wx-jssdk';
import {
	TESTING
} from './test';
import {
	originalData,
	uniHideLoading,
	uniShowLoading
} from './commonFuncs';

import store from '../store/index.js';

const QQMapWX = new QQMapSdk({
	key: Config.TencentMapKey,
});

/**
 * 权限校验
 */
/**
 *
 * @param showToast 要不要提示用户
 * @param toRedirect
 * @returns boolean {boolean}
 * 登陆了没
 */
export function didntLoggedIn(showToast = true, toRedirect = true) {
	let token = uniGetStorageSync(TOKEN_key);
	if (!token) {
		if (!USER_ORIENTED && toRedirect) {
			// 如果是招商端, 需要你一直登录
			uniRedirect('/login');
		}
		if (showToast) {
			uniShowToast('请先登录', false);
		}
		return true;
	}
	return false;
}

/**
 *  字符串工具集, js 工具集
 */
export function checkStringBlank(str) {
	String.prototype.trim = function() {
		return this.replace(/(^\s*)|(\s*$)/g, '');
	};
	return !str.trim(); // 空则true , 非空则false
}

let triedTimes = 0;

export function logout(_this, toReLaunch = true) {
	uniSetUser(_this, undefined);
	uniSetToken(_this, '');
	if (toReLaunch) {
		setTimeout(() => {
			uniReLaunch('/login');
		}, TOAST_DURATION);
	}
}

/**
 * 从类似 '2020-11-20 11:37:00'的字符串中获取事件
 * @param str
 * @return array[] // arr[0]: 11月20日, arr[1]: 11:37
 * @eg:var MonthDay = calendar.monthDays(1987,9) ;//MonthDay=29
 */
export function getTimeFromString(str) {
	let res = [];
	let two = str.split(' ');
	let date = two[0].split('-'); // two[0]: 11-20
	for (let i = 0, len = date.length; i < len; i++) {
		let val = date[i];
		if (val.startsWith('0')) {
			date[i] = val.replace('0', '');
		}
	}
	res.push(date[0] + '月' + date[1] + '日');
	res.push(two[1]);
	return res;
}

export function sayHi() {
	// console.log('hi')
}

// 深度比较, [] === [] 会返回false
export function deepEqual(x, y) {
	if (x === y) {
		return true;
	} else if (
		typeof x == 'object' &&
		x != null &&
		typeof y == 'object' &&
		y != null
	) {
		if (Object.keys(x).length !== Object.keys(y).length) return false;

		for (var prop in x) {
			if (y.hasOwnProperty(prop)) {
				if (!deepEqual(x[prop], y[prop])) return false;
			} else return false;
		}

		return true;
	} else return false;
}

export function ifNoneThenBlank(str) {
	if (str === 'none') {
		return '';
	} else {
		return str;
	}
}

function indexOf(arr, val) {
	for (var i = 0; i < arr.length; i++) {
		if (arr[i] === val) return i;
	}
	return -1;
}

// array 删除 数组内的某个元素
export function removeValOf(arr, val) {
	let index = arr.findIndex((item) => deepEqual(item, val));
	if (index > -1) {
		arr.splice(index, 1);
		return true;
	}
	return false;
}

/**
 * uni app 常用api
 */
export function uniReLaunch(url, cb) {
	return new Promise((resolve) => {
		if (url)
			uni.reLaunch({
				url: '/pages' + url,
				complete: (res) => {
					// console.log(res)
					uniHideLoading();
					cb && cb();
					resolve(res);
				},
			});
	});
}

// 使用call 来调用
export function resetComponentData(cb) {
	let res = Object.assign(this.$data, this.$options.data());
	// console.log(res)
	cb && cb();
}

// 求大神告诉jzy为什么这个不生效
export function resetVueData(exArr) {
	// console.log(this.$data, this.$options.data())
	for (let prop in this.$data) {
		if (!exArr.includes(prop)) {
			console.log(prop);
			this.$data.prop = originalData(this).prop || '';
		}
	}
}

export function uniGetStorageSync(key, reset = false) {
	return uni.getStorageSync(key);
}

export function uniSetStorageSync(key, val) {
	uni.setStorageSync(key, val);
}

// 招商端专用设置user信息
export function uniSetUser(_this, userInfo) {
	// 更新 vuex中的user
	if (_this) {
		_this.$store.commit('changeUser', userInfo);
	} else {
		store.commit('changeUser', userInfo);
	}
	uniSetStorageSync(CURRENT_USER_KEY, userInfo);
	console.log("用户信息缓存",CURRENT_USER_KEY)

}

// 招商端专用设置 token信息
export function uniSetToken(_this, token) {
	if (_this) {
		_this.$store.commit('changeToken', token);
	} else {
		store.commit('changeToken', token);
	}
	uniSetStorageSync(TOKEN_key, token);
}

export function uniSwitchTab(url, cb) {
	uni.switchTab({
		url: '/pages' + url,
		fail: function(res) {
			// console.log(res)
		},
		success: (res) => {
			cb && cb();
		},
	});
}

export function uniRedirect(url, cb) {
	// console.log('redirected');
	uni.redirectTo({
		url: '/pages' + url,
		success: (res) => {
			cb && cb();
		},
		fail: function(res) {
			// console.log(res)
		},
	});
}

export function uniSetNavigationBarTitle(title, opt) {
	uni.setNavigationBarTitle({
		title: title,
		...opt,
	});
}

export function uniChooseImage(opt) {
	uni.chooseImage({
		count: 1,
		sizeType: ['compressed'],
		sourceType: ['album', 'camera'],
		success: (res) => {
			// console.log(res)
		},
		fail: (err) => {
			// console.log('chooseImage fail', err)
			alert('图片')
			// #ifdef APP-PLUS || H5
			uni.getSetting({
				success: (res) => {
					let authStatus = res.authSetting['scope.album'];
					if (!authStatus) {
						uni.showModal({
							title: '授权失败',
							content: 'Hello uni-app需要从您的相册获取图片，请在设置界面打开相关权限',
							success: (res) => {
								if (res.confirm) {
									uni.openSetting();
								}
							},
						});
					}
				},
			});
			// #endif
		},
		...opt,
	});
}

export function uniPreviewImage(imageArr, current) {
	uni.previewImage({
		urls: imageArr,
		current: current || 0,
		longPressActions: {
			itemList: ['保存图片'],
			success: (data) => {
				//data.tapIndex按钮下标 ，data.index图片下标
				if (data.tapIndex == 0) {
					uni.saveImageToPhotosAlbum({
						filePath: imageArr[data.index],
						success: function() {
							uniShowToast('保存成功', false);
						},
					});
				}
			},
			fail: (err) => {},
		},
	});
}

export function uniPageScrollTo(val, cb) {
	return new Promise((resolve, reject) => {
		uni.pageScrollTo({
			duration: 0,
			scrollTop: val, //滚动到实际距离是元素距离顶部的距离减去最外层盒子的滚动距离
			success: (res) => {
				// console.log('滚动成功:', res)
				cb && cb();
				resolve(res);
			},
			fail: (res) => {
				// console.log('滚动fail:', res)
				reject(res);
			},
		});
	});
}

// 仅适用于上传图片后快速从json字符串中解析出图片地址,
/*
  return : photo url on server
 */
export function parsePhotoUrlFrom(str) {
	return JSON.parse(str).data.url;
}

export function uniUploadFile(filePath, cb, showToast = true) {
	uni.uploadFile({
		url: baseApi_('/upload'),
		filePath: filePath,
		fileType: 'image',
		name: 'image',
		success: ({
			data
		}) => {
			cb && cb(data);
			if (showToast) {
				uni.showToast({
					title: '上传成功',
					icon: 'success',
					duration: SHORT_TOAST_DURATION,
				});
			}
		},
		fail: (err) => {
			// console.log('uploadImage fail', err);
			uni.showModal({
				content: err.errMsg,
				showCancel: false,
			});
		},
	});
}

export function uniMakePhoneCall(phoneNumber) {
	if (phoneNumber === '') {
		d_uniShowToast({
			title: '暂无号码',
		});
	} else {
		uni.makePhoneCall({
			phoneNumber: phoneNumber,
		});
	}
}

function getChatName() {
	if (USER_ORIENTED) {
		if (TESTING) {
			return '后端没给用户名';
		} else {
			return '启租用户';
		}
	} else {
		if (TESTING) {
			return '后端没给用户名的招商人员';
		} else {
			return '招商人员';
		}
	}
}

// 获取聊天用户信息
export function rongGetChatterProfile(targetId) {
	let url, postData;
	if (USER_ORIENTED) {
		url = '/get_rongcloud_merchant';
		postData = {
			merchant_id: targetId,
		};
	} else {
		url = '/get_rongcloud_user';
		postData = {
			user_id: targetId,
		};
	}

	return new Promise((resolve, reject) => {
		let resPerson;
		resPerson = uniGetStorageSync(PROFILE_OF + targetId) || {};

		if (resPerson.rongcloud_id && resPerson.name) {
			let date = new Date();

			// 每1天获取更新一次用户信息,
			date.setTime(date.getTime() - 24 * 60 * 60 * 1000);
			if (date.getTime() < resPerson.lastUpdateTime) {
				// console.log('local: ', resPerson);
				resolve(resPerson);
				return
			}
		}

		uniRequest('', postData, {
			url: ONLINE_SERVER_USER + url,
			success: ({
				data
			}) => {
				if (data.code === 200) {
					// console.log('cloud profile', url, postData);
					// console.log('res data', data);
					resPerson = data.data || {};
					resPerson.rongcloud_id = targetId;
					// console.log('resPerson: ', resPerson);
					// 保存用户信息到本地
					uniSetStorageSync(PROFILE_OF + targetId, {
						...resPerson,
						lastUpdateTime: new Date().getTime(),
					});
					// setProfile_local(resPerson);
					resolve(resPerson);
				} else {
					console.warn('错误:', data);
					resolve({});
				}
			},
		});
	});
}

export function getCurrentUserProfile() {
	if (didntLoggedIn(false)) return;
	return new Promise((resolve) => {
		if (USER_ORIENTED) {
			tokenRequest(
				'/user_info', {}, {
					success: ({
						data
					}) => {
						if (data.code === 200) {
							uniSetStorageSync(CURRENT_USER_KEY, data.data);
							resolve(data.data);
						}
					},
				}
			);
		} else {}
	});
}

export function hxGetUserProfile(hxId) {
	let resUserProfile;
	return new Promise((resolve) => {
		tokenRequest(
			'/get_easemob_merchant', {
				easemob_account_password: hxId,
			}, {
				success: ({
					data
				}) => {
					if (data.code === 200) {
						let res = data.data[0];
						resUserProfile = {
							...res,
							easemob_account_password: hxId,
							name: (res && res.name) || '招商人员',
						};

						resolve(resUserProfile);
					} else {
						console.warn('错误');
						resolve({});
					}
				},
			}
		);
	});
}

/**
 * 定位相关
 */

export function judgeIosPermissionLocation() {
	// #ifdef APP-PLUS
	var result = false;
	uni.getSystemInfo({
		complete: (res) => {
			// console.log('手机', res.platform)
			if (res.platform != 'ios') {
				// console.log('我不是ios')
			} else {
				if (!plus) {
					return;
				}
				var cllocationManger = plus.ios.import('CLLocationManager');
				// console.log('cllocationManger', cllocationManger)
				var status = cllocationManger.authorizationStatus();
				result = status != 2;
				// console.log("定位权限开启：" + result);
				// 以下代码判断了手机设备的定位是否关闭，推荐另行使用方法 checkSystemEnableLocation
				var enable = cllocationManger.locationServicesEnabled();
				status = cllocationManger.authorizationStatus();
				// console.log("enable:" + enable);
				// console.log("status:" + status);
				if (enable && status != 2) {
					result = true;
					// console.log("iOS手机定位服务已开启且已授予定位权限");
				} else {
					uniShowToast('iOS: 未开启定位服务', false);
					// console.log("手机系统的定位没有打开或未给予定位权限");
				}
				plus.ios.deleteObject(cllocationManger);
				return result;
			}
		},
	});
	// #endif
}

/**
 * @description 获取定位json并把成功结果存到storage, 提醒用户失败结果
 *
 * @param toLocation 是否要到定位页面
 * @param toFailToast 是否提示用户失败结果
 * @returns {Promise<>}
 */
export function proGetLocation(toLocation = false, toFailToast = true) {
	let resLat;
	let resLon;

	return new Promise((resolve, reject) => {
		uni.getLocation({
			type: 'gcj02',
			geocode: true,
			/**
			 * @description: 返回一个解析好的地址 :{address, city, province}
			 */
			success: (res) => {
				console.log('地图', res)
				resLat = res.latitude;
				resLon = res.longitude;
				// 解析地址
				// #ifndef H5
				QQMapWX.reverseGeocoder({
					location: {
						latitude: resLat,
						longitude: resLon,
					},
					success: (res) => {
						// res结构详见qqMap.json
						let {
							ad_info
						} = res.result;
						// console.log("qq Map获取定位成功", ad_info);
						uniSetStorageSync(MY_LOCATION, ad_info);
						uniSetStorageSync(FINE_LOCATION, ad_info);
						console.log('FINE_LOCATION: ', uniGetStorageSync(
							FINE_LOCATION));
						// console.log('腾讯定位',ad_info)
						resolve(ad_info); // 返回 {address, city, province}的成功结果
					},
					fail: function(res) {
						reject(res);
					},
				});
				// #endif
				// #ifdef H5
				uniRequest('/inverse_address', {
					location: `${resLat},${resLon}`
				}, {
					success: (res) => {
						// res结构详见qqMap.json
						let {
							ad_info
						} = res.data.data.result;
						// console.log("qq Map获取定位成功", ad_info);
						uniSetStorageSync(MY_LOCATION, ad_info);
						uniSetStorageSync(FINE_LOCATION, ad_info);
						console.log('FINE_LOCATION: ', uniGetStorageSync(
							FINE_LOCATION));
						// console.log('腾讯定位',ad_info)
						resolve(ad_info); // 返回 {address, city, province}的成功结果
					},
					fail: function(res) {
						reject(res);
					},
				})
				// #endif
			},
			fail: (res) => {
				reject(res);
			},
		});
	});
}

// 首页定位初始化
export function homeInitLocation(succesCb) {
	if (!this.address.city) {}
}

export function isChinese(temp) {
	var re = /[^\u4e00-\u9fa5]/;
	return !re.test(temp);
}

export function passCheckLocationResult(address) {
	if (!address.city) {
		return;
	}
	if (!isChinese(address.city.toString())) {
		d_uniShowToast({
			title: '检测到定位结果不是中文, 请手动选择',
		});
		address.city = '';
		return false;
	}
	return true;
}

// 使用方法myThrottle.call(this, ()=>{}, 1000)
export function myThrottle(fn, delay = 500) {
	if (this.throttleTimer) {
		return;
	}
	this.throttleTimer = setTimeout(() => {
		fn();
		clearTimeout(this.throttleTimer);
		this.throttleTimer = null;
	}, delay);
}

// 防抖, (例子说明法)只有用户停止输入才进行ajax请求
export function myDebounce(fn, delay = 500, timer = null) {
	// timer是在闭包中的
	if (timer) {
		clearTimeout(timer);
		timer = null;
	}
	timer = setTimeout(() => {
		fn.apply(this, arguments);
		clearTimeout(timer);
		timer = null;
	}, delay);
}

function afterCancelSuccess() {
	uniShowLoading('注销成功, 跳转中...', true, {
		success: async (res) => {
			console.log(res);
			setTimeout(() => {
				// console.log('注销前: ', uniGetStorageSync(TOKEN_key));
				clearUserInfo(this);
				uniReLaunch('/my/my');
			}, TOAST_DURATION);
		},
	});
}

/**
 * 需要的mixin: chatMixin, 调用方法cancelAccount.call(this, argsHere)
 * fakeCancel: 测试专用, 不过现在看来可以不用了
 * 函数逻辑操作:
 *  1 - 删除所有聊天会话,
 *  2 - 删除所有用户信息,
 */
export function cancelAccount(fakeCancel, showModal = true) {
	if (showModal) {
		uni.showModal({
			title: '注销账号',
			content: '注销后，数据将重置，可重新注册。请确保所有交易已完结且无纠纷。\n' +
				'请谨慎操作。',
			success: async (res) => {
				if (res.confirm) {
					confirmOperation.call(this);
				} else if (res.cancel) {
					// console.log('用户点击取消');
				}
			},
		});
	}

	async function confirmOperation() {
		if (showModal) {
			uniShowLoading('操作中, 请勿退出');
			// console.log('用户点击确定');
		}
		tokenRequest(
			'/user_cancel_account', {}, {
				success: async ({
					data
				}) => {
					// console.log('注销结果: ', data);
					if (data.code === 200) {
						// 删除所有聊天记录
						let res = await this.deleteAllConversation();
						console.log('删除结果: ', res);
						afterCancelSuccess.call(this);
					} else {
						console.log(data);
						uniShowToast(data.msg, true, {
							duration: TOAST_DURATION + 2000,
						});
					}
				},
			}
		);
	}
}

// 用法 exitLogin.call(any)
export async function exitLogin(msg) {
	clearUserInfo(this);
	// 退出登录
	if (USER_ORIENTED) {
		await uniReLaunch('/my/my');
	} else {
		await uniReLaunch('/login/login');
	}
	if (msg) uniShowToast(msg, true, {
		duration: TOAST_DURATION + 2000
	});
}

//  usage: pass vue instance to vm
export function authRouterGuard(vm) {
	return new Promise(async (resolve, reject) => {
		let didntLoggedIn = !uniGetStorageSync(TOKEN_key);
		if (didntLoggedIn) {
			if (USER_ORIENTED) {
				// 用户端
				clearUserInfo(vm);
				reject();
			} else {
				// 招商端
				exitLogin.call(vm, '请登录');
				reject();
			}
		}
		tokenRequestP('/user_info', {}, 'POST').then((data) => {
			console.log("测试登录",data)
			if (data.code === 506) {
				exitLogin.call(vm, data.msg);
				reject();
			}
			resolve();
		})
	});
}

/**
 * @description: password === passwordAgain?
 * @param form
 * @returns {boolean} true: passed; false: unpassed
 */
export function pass_passwordAgainCheck(form) {
	if (form.password !== form.passwordAgain) {
		uniShowToast('两次输入的密码不一致', false);
		return false;
	}
	return true;
}

// 判空
export function isBlank(obj) {
	if (obj === '') return false;
	if ([null, undefined, NaN, false].includes(obj)) return false;
	if (isArray(obj) && obj.length === 0) return false;
	return true
}

// 判断arr是否为一个数组，返回一个bool值
export function isArray(arr) {
	return Object.prototype.toString.call(arr) === '[object Array]';
}

export function uniSetUserRight(userId,auth_type) {
	getUserRight(userId,auth_type)
}

export function uniConfigRight(authList,auth_type) {
	var pendingData = { 
							goodsReleaseStatus:'-1',         //物品放行
							accessCardStatus:'-1',          //门禁卡
							whiteCardStatus:'-1',           //白卡
							parkingCardStatus:'-1',         //停车位
							airConditionStatus:'-1',        //空调加时
							conferenceRoomStatus:'-1',      //会议室预约
							repairStatus:'-1',              //维修服务
							decorationStatus:'-1',          //装修服务
							invoiceStatus:'-1',             //发票办理
							costServiceStatus:'-1',         //收费服务
							goodsBorrowStatus:'-1',         //物品借用
							knotCommissionStatus:'-1',      //中介结佣
							deliverHouseStatus:'-1',        //交房
							exchangeRentStatus:'-1',        //退换租
							renewalStatus:'-1',             //续租
							onlinePayStatus:'-1',            //缴费服务
					}
	var blockAuthDetail = { "goodsRelease":{"right":false,"primeAuth":-1},
							"accessCard":{"right":false,"primeAuth":-1},
							"whiteCard":{"right":false,"opeCommRight":false,"engCommRight":false,"primeAuth":-1},
							"parkingCard":{"right":false,"primeAuth":-1},
							"airCondition":{"right":false,"opeCommRight":false,"engCommRight":false,"refundRight":false,"primeAuth":-1},
							"conferenceRoom":{"right":false,"opeCommRight":false,"refundRight":false,"primeAuth":-1},
							"repair":{"right":false,"opeCommRight":false,"engCommRight":false,"primeAuth":-1},
							"decoration":{"right":false,"opeCommRight":false,"engCommRight":false,"engVerRight":false,"mapCommRight":false,"mapVerRight":false,"leaderVerRight":false,"primeAuth":-1},
							"invoice":{"right":false,"opeCommRight":false,"finanCommRight":false,"primeAuth":-1},
							"costService":{"right":false,"primeAuth":-1},
							"goodsBorrow":{"right":false,"primeAuth":-1},
							"knotCommission":{"right":false,"opeVerRight":false,"finanCommRight":false,"finanVerRight":false,"leaderVerRight":false,"primeAuth":-1},
							"deliverHouse":{"right":false,"primeAuth":-1},
							"exchangeRent":{"right":false,"opeCommRight":false,"engCommRight":false,"finanVerRight":false,"primeAuth":-1}, 
							"renewal":{"right":false,"opeCommRight":false,"opeVerRight":false,"finanCommRight":false,"contractCommRight":false,"primeAuth":-1}, 
	};
	authList.forEach((item,key) => {
		switch(item.authId) {
			 case 1:
				blockAuthDetail = { "goodsRelease":{"right":true,"primeAuth":2},
									"accessCard":{"right":true,"primeAuth":2},
									"whiteCard":{"right":true,"opeCommRight":true,"engCommRight":false,"primeAuth":2},
									"parkingCard":{"right":true,"primeAuth":2},
									"airCondition":{"right":true,"opeCommRight":true,"engCommRight":false,"refundRight":false,"primeAuth":2},
									"conferenceRoom":{"right":true,"opeCommRight":true,"refundRight":false,"primeAuth":2},
									"repair":{"right":true,"opeCommRight":true,"engCommRight":false,"primeAuth":2},
									"decoration":{"right":true,"opeCommRight":true,"engCommRight":false,"engVerRight":false,"mapCommRight":false,"mapVerRight":false,"leaderVerRight":false,"primeAuth":2},
									"invoice":{"right":true,"opeCommRight":true,"finanCommRight":false,"primeAuth":2},
									"costService":{"right":true,"primeAuth":2},
									"goodsBorrow":{"right":true,"primeAuth":2},
									"knotCommission":{"right":false,"opeVerRight":false,"finanCommRight":false,"finanVerRight":false,"leaderVerRight":false,"primeAuth":2},
									"deliverHouse":{"right":true,"primeAuth":2},
									"exchangeRent":{"right":true,"opeCommRight":true,"engCommRight":false,"primeAuth":2}, 
									"renewal":{"right":true,"opeCommRight":true,"opeVerRight":true,"finanCommRight":false,"contractCommRight":false,"primeAuth":1},
				};
				blockAuthDetail.knotCommission.opeVerRight = true   //运营主管审批中介结佣权限
				blockAuthDetail.knotCommission.right = true         //运营主管显示中介结佣模块权限
				if(auth_type == 1){
					blockAuthDetail.knotCommission.primeAuth = 1    //配置中介结佣模块主角色
				}
				
				pendingData.goodsReleaseStatus = '-1'        //物品放行
				pendingData.accessCardStatus = '-1'          //门禁卡
				pendingData.whiteCardStatus = '-1'          //白卡
				pendingData.parkingCardStatus = '-1'         //停车位
				pendingData.airConditionStatus = '-1'        //空调加时
				pendingData.conferenceRoomStatus = '-1'      //会议室预约
				pendingData.repairStatus = '-1'             //维修服务
				pendingData.decorationStatus = '-1'         //装修服务
				pendingData.invoiceStatus = '-1'             //发票办理
				pendingData.costServiceStatus = '-1'         //收费服务
				pendingData.goodsBorrowStatus = '-1'         //物品借用
				pendingData.knotCommissionStatus = '0'      //中介结佣
				pendingData.deliverHouseStatus = '-1'        //交房
				pendingData.exchangeRentStatus = '-1'        //退换租
				pendingData.renewalStatus = '5'             //续租
			    break;
			 case 2:
				blockAuthDetail = { "goodsRelease":{"right":true,"primeAuth":2},
									"accessCard":{"right":true,"primeAuth":2},
									"whiteCard":{"right":true,"opeCommRight":true,"engCommRight":false,"primeAuth":2},
									"parkingCard":{"right":true,"primeAuth":2},
									"airCondition":{"right":true,"opeCommRight":true,"engCommRight":false,"refundRight":false,"primeAuth":2},
									"conferenceRoom":{"right":true,"opeCommRight":true,"refundRight":false,"primeAuth":2},
									"repair":{"right":true,"opeCommRight":true,"engCommRight":false,"primeAuth":2},
									"decoration":{"right":true,"opeCommRight":true,"engCommRight":false,"engVerRight":false,"mapCommRight":false,"mapVerRight":false,"leaderVerRight":false,"primeAuth":2},
									"invoice":{"right":true,"opeCommRight":true,"finanCommRight":false,"primeAuth":2},
									"costService":{"right":true,"primeAuth":2},
									"goodsBorrow":{"right":true,"primeAuth":2},
									"knotCommission":{"right":false,"opeVerRight":false,"finanCommRight":false,"finanVerRight":false,"leaderVerRight":false,"primeAuth":2},
									"deliverHouse":{"right":true,"primeAuth":2},
									"exchangeRent":{"right":true,"opeCommRight":true,"engCommRight":false,"primeAuth":2}, 
									"renewal":{"right":true,"opeCommRight":true,"opeVerRight":false,"finanCommRight":false,"contractCommRight":false,"primeAuth":2},
				};
				pendingData.goodsReleaseStatus = '0,1'        //物品放行
				pendingData.accessCardStatus = '0,1'          //门禁卡
				pendingData.whiteCardStatus = '0,2,5'          //白卡
				pendingData.parkingCardStatus = '0,1'         //停车位
				pendingData.airConditionStatus = '0,3'        //空调加时
				pendingData.conferenceRoomStatus = '0,3'      //会议室预约
				pendingData.repairStatus = '0,1'             //维修服务
				pendingData.decorationStatus = '1,7'         //装修服务
				pendingData.invoiceStatus = '0,2'             //发票办理
				pendingData.costServiceStatus = '0,1'         //收费服务
				pendingData.goodsBorrowStatus = '0,3'         //物品借用
				pendingData.deliverHouseStatus = '1'        //交房
				pendingData.exchangeRentStatus = '0,2,4,7'        //退换租
				pendingData.renewalStatus = '2,4,8'             //续租
		        break;
			 case 3:
			    blockAuthDetail.knotCommission.right = true  //招商专员显示中介结佣模块权限
				if(auth_type == 3){
					blockAuthDetail.knotCommission.primeAuth = 3 //配置中介结佣模块主角色
				}
			    break;
			 case 4:
			    blockAuthDetail.knotCommission.right = true  //招商主管显示中介结佣模块权限
				if(auth_type == 4){
					blockAuthDetail.knotCommission.primeAuth = 4 //配置中介结佣模块主角色，注意招商主管默认拥有专员角色
				}
		        break;
			 case 5:
				blockAuthDetail.airCondition.right = true  //财务主管显示空调加时模块权限
				blockAuthDetail.airCondition.refundRight = true  //退款权限
	
				blockAuthDetail.conferenceRoom.right = true  //财务主管显示会议室预约模块权限
				blockAuthDetail.conferenceRoom.refundRight = true  //退款权限
	
				blockAuthDetail.invoice.right = true  //财务主管显示发票模块权限
				blockAuthDetail.invoice.finanCommRight = true  //财务基础操作权限
	
				blockAuthDetail.renewal.right = true  //财务主管显示续租模块权限
				blockAuthDetail.renewal.finanCommRight = true  //财务基础操作权限
	
				blockAuthDetail.exchangeRent.right = true  //财务显示退换租模块权限
				blockAuthDetail.exchangeRent.finanVerRight = true  //财务基础操作权限	
	
			    blockAuthDetail.knotCommission.right = true  //财务主管显示中介结佣模块权限
				blockAuthDetail.knotCommission.finanCommRight = true  //财务基础操作权限
				blockAuthDetail.knotCommission.finanVerRight = true  //财务主管审批中介结佣权限
				
				
				if(auth_type == 5){
				    blockAuthDetail.airCondition.primeAuth = 5 //配置中介结佣模块主角色为财务主管
				    blockAuthDetail.conferenceRoom.primeAuth = 5 //配置会议室预约模块主角色为财务主管
					blockAuthDetail.invoice.primeAuth = 5 //配置会议室预约模块主角色为财务主管
					blockAuthDetail.renewal.primeAuth = 5 //续租模块主角色为财务主管
					blockAuthDetail.exchangeRent.primeAuth = 5 //续租模块主角色为财务主管
					blockAuthDetail.knotCommission.primeAuth = 5 //配置中介结佣模块主角色为财务主管
				}
				
				pendingData.airConditionStatus = '-1'        //空调加时
				pendingData.invoiceStatus = '-1'             //发票办理
				pendingData.knotCommissionStatus = '2'      //中介结佣
				pendingData.exchangeRentStatus = '-1'        //退换租
				pendingData.onlinePayStatus = '-1'             //缴费服务
		        break;
			 case 6:
				blockAuthDetail.airCondition.right = true  //财务专员显示空调加时模块权限
				blockAuthDetail.airCondition.refundRight = true  //退款权限
	
				blockAuthDetail.conferenceRoom.right = true  //财务专员显示会议室预约模块权限
				blockAuthDetail.conferenceRoom.refundRight = true  //退款权限				
	
				blockAuthDetail.invoice.right = true  //财务专员显示发票模块权限
				blockAuthDetail.invoice.finanCommRight = true  //财务基础操作权限
	
				blockAuthDetail.renewal.right = true  //财务主管显示续租模块权限
				blockAuthDetail.renewal.finanCommRight = true  //财务基础操作权限
				
				blockAuthDetail.exchangeRent.right = true  //财务显示退换租模块权限
				blockAuthDetail.exchangeRent.finanVerRight = true  //财务基础操作权限	
				
			    blockAuthDetail.knotCommission.right = true  //财务专员显示中介结佣模块权限
				blockAuthDetail.knotCommission.finanCommRight = true  //财务基础操作权限
				
				if(auth_type == 6){
				    blockAuthDetail.airCondition.primeAuth = 6 //配置中介结佣模块主角色为财务专员
				    blockAuthDetail.conferenceRoom.primeAuth = 6 //配置会议室预约模块主角色为财务专员
					blockAuthDetail.invoice.primeAuth = 6 //配置会议室预约模块主角色为财务专员
					blockAuthDetail.renewal.primeAuth = 6 //续租模块主角色为财务主管
					blockAuthDetail.exchangeRent.primeAuth = 6 //续租模块主角色为财务主管
					blockAuthDetail.knotCommission.primeAuth = 6 //配置中介结佣模块主角色为财务专员
				}
				
				pendingData.airConditionStatus = '5'        //空调加时
				pendingData.invoiceStatus = '1'             //发票办理
				pendingData.exchangeRentStatus = '6'        //退换租
				pendingData.renewalStatus = '7'             //续租
				pendingData.onlinePayStatus = '1,2'             //缴费服务
		        break;
			 case 7:
				blockAuthDetail.whiteCard.right = true  //工程主管显示白卡模块权限
				blockAuthDetail.whiteCard.engCommRight = true  //工程基础操作权限
			 
				blockAuthDetail.airCondition.right = true  //工程主管显示空调加时模块权限
				blockAuthDetail.airCondition.engCommRight = true  //工程基础操作权限
	
				blockAuthDetail.repair.right = true  //工程主管显示维修模块权限
				blockAuthDetail.repair.engCommRight = true  //工程基础操作权限				
	
				blockAuthDetail.decoration.right = true  //工程主管显示装修模块权限
				blockAuthDetail.decoration.engCommRight = true  //工程基础操作权限
				blockAuthDetail.decoration.engVerRight = true  //工程主管审批操作权限
	
				blockAuthDetail.exchangeRent.right = true  //工程主管显示退换租模块权限
				blockAuthDetail.exchangeRent.engCommRight = true  //工程基础操作权限			
	
				if(auth_type == 7){
				    blockAuthDetail.whiteCard.primeAuth = 7 //配置白卡模块主角色为工程主管
				    blockAuthDetail.airCondition.primeAuth = 7 //配置空调加时模块主角色为工程主管
					blockAuthDetail.repair.primeAuth = 7 //配置维修模块主角色为工程主管
					blockAuthDetail.decoration.primeAuth = 7 //配置装修模块主角色为工程主管
					blockAuthDetail.exchangeRent.primeAuth = 7 //配置退换租模块主角色为工程主管
				}
				pendingData.whiteCardStatus = '-1'          //白卡
				pendingData.airConditionStatus = '-1'        //空调加
				pendingData.repairStatus = '-1'             //维修服务
				pendingData.decorationStatus = '2'         //装修服务
				pendingData.exchangeRentStatus = '-1'        //退换租
		        break;
			 case 8:
				blockAuthDetail.whiteCard.right = true  //工程专员显示白卡模块权限
				blockAuthDetail.whiteCard.engCommRight = true  //工程基础操作权限
			 
				blockAuthDetail.airCondition.right = true  //工程专员显示空调加时模块权限
				blockAuthDetail.airCondition.engCommRight = true  //工程基础操作权限
	
				blockAuthDetail.repair.right = true  //工程专员显示维修模块权限
				blockAuthDetail.repair.engCommRight = true  //工程基础操作权限				
	
				blockAuthDetail.decoration.right = true  //工程专员显示装修模块权限
				blockAuthDetail.decoration.engCommRight = true  //工程基础操作权限
	
				blockAuthDetail.exchangeRent.right = true  //工程专员显示退换租模块权限
				blockAuthDetail.exchangeRent.engCommRight = true  //工程基础操作权限			
	
				if(auth_type == 8){
				    blockAuthDetail.whiteCard.primeAuth = 8 //配置白卡模块主角色为工程专员
				    blockAuthDetail.airCondition.primeAuth = 8 //配置空调加时模块主角色为工程专员
					blockAuthDetail.repair.primeAuth = 8 //配置维修模块主角色为工程专员
					blockAuthDetail.decoration.primeAuth = 8 //配置装修模块主角色为工程专员
					blockAuthDetail.exchangeRent.primeAuth = 8 //配置退换租模块主角色为工程专员
				}
				pendingData.whiteCardStatus = '1'          //白卡
				pendingData.airConditionStatus = '4,7'        //空调加
				pendingData.repairStatus = '2,4'             //维修服务
				pendingData.decorationStatus = '8'         //装修服务
				pendingData.exchangeRentStatus = '1'        //退换租
		        break;
			 case 9:
				blockAuthDetail.decoration.right = true  //绘图主管显示装修模块权限
				blockAuthDetail.decoration.mapCommRight = true  //绘图基础操作权限
				blockAuthDetail.decoration.mapVerRight = true  //绘图主管审批操作权限
	
				if(auth_type == 9){
					blockAuthDetail.decoration.primeAuth = 9 //配置装修模块主角色为绘图主管
				}
				pendingData.decorationStatus = '4'         //装修服务
		        break;
			 case 10:
				blockAuthDetail.decoration.right = true  //绘图专员显示装修模块权限
				blockAuthDetail.decoration.mapCommRight = true  //绘图基础操作权限
	
				if(auth_type == 10){
					blockAuthDetail.decoration.primeAuth = 10 //配置装修模块主角色为绘图专员
				}
				pendingData.decorationStatus = '3'         //装修服务
		        break;
			 case 11:
				blockAuthDetail.renewal.right = true  //合同主管显示装修模块权限
				blockAuthDetail.renewal.contractCommRight = true  //合同基础操作权限
	
				if(auth_type == 11){
					blockAuthDetail.renewal.primeAuth = 11 //配置续租模块主角色为合同主管
				}
				pendingData.renewalStatus = '-1'             //续租
				pendingData.deliverHouseStatus = '-1'        //交房
		        break;
			 case 12:
				blockAuthDetail.renewal.right = true  //合同专员显示装修模块权限
				blockAuthDetail.renewal.contractCommRight = true  //合同基础操作权限
	
				if(auth_type == 12){
					blockAuthDetail.renewal.primeAuth = 12 //配置续租模块主角色为合同专员
				}
				pendingData.renewalStatus = '1'             //续租
				pendingData.deliverHouseStatus = '0'        //交房
		        break;
			 case 13:
				blockAuthDetail.decoration.right = true  //项目总监显示装修模块权限
				blockAuthDetail.decoration.leaderVerRight = true  //项目总监审批权限
				
				blockAuthDetail.knotCommission.right = true  //项目总监显示中介结佣模块权限
				blockAuthDetail.knotCommission.leaderVerRight = true  //项目总监审批权限
	
				if(auth_type == 13){
					blockAuthDetail.decoration.primeAuth = 13 //配置装修模块主角色为项目总监
					blockAuthDetail.knotCommission.primeAuth = 13 //配置中介结佣模块主角色为项目总监
				}
				pendingData.decorationStatus = '0,6'         //装修服务
				pendingData.knotCommissionStatus = '1'      //中介结佣
		        break;
			 default:
			    break;
		} 
	});
	uni.setStorageSync("userRight", blockAuthDetail);
	uni.setStorageSync("pendingData", pendingData);
	console.log("配置后的user 各模块主角色及操作权限",blockAuthDetail);
}
